package com.ycg.blog.common;

import cn.dev33.satoken.exception.NotLoginException;
import com.ycg.blog.exception.IpBackException;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author YCG
 * @date 2024-03-13 14:27
 * @description 全局异常处理器
 */
@Order(1)
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(IpBackException.class)
    public R<String> handler(IpBackException ex) {
        return R.error(ex.getMessage(),110);
    }

    @ExceptionHandler(NotLoginException.class)
    public R<String> handler(NotLoginException ex) {
        return R.error(ex.getMessage(),ex.getCode());
    }


}
